package model

import (
	"fmt"

	"github.com/go-redis/redis/v8"
	"github.com/rabbitmq/amqp091-go"
)

type Communicationlink struct {
	HostGroupId     int
	Id              int
	RtuId           int
	AnaPoints       []*Point
	StaPoints       []*Point
	AccPoints       []*Point
	RedisCli        *redis.Client
	RabbitmqChannel *amqp091.Channel
}

// 定义常量
const (
	ANA_POINT_TYPE = "analoginput"
	STA_POINT_TYPE = "statusinput"
)

var (
	ANA_POINT_INDEX = "analoginput&rtuid&pointnum:%d&%d"
	STA_POINT_INDEX = "statusinput&rtuid&pointnum:%d&%d"
	ACC_POINT_INDEX = "accmulatorinput&rtuid&pointnum:%d&%d"
)

type Point struct {
	Id                int
	PointNum          int
	EquTid            int
	EquId             int
	MeaId             int
	Communicationlink *Communicationlink
	Counter           *int64
	Timestamp         string
	IndexParttern     *string
}

func (p *Point) GetIoTDBPath() string {
	return fmt.Sprintf("root.history._%d._%d._%d", p.EquTid, p.EquId, p.MeaId)
}

func (p *Point) String() string {
	return fmt.Sprintf("point.type=[%s], point.id=[%d], point.path=[%s]", (*p.IndexParttern)[:11], p.Id, p.GetIoTDBPath())
}
